package com.project.dao.impl;

import com.project.bean.LinkBean;
import com.project.dao.ILinkDao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.List;

public class LinkDaoImols implements ILinkDao {
    @Override
    public void add(LinkBean linkBean) {
//       创建链接对象
        Connection con = null;
//        创建执行sql语句
        PreparedStatement ps = null;



        try {
            //        加载链接
            Class.forName("com.mysql.jdbc.Driver");

//            链接对象
            con = DriverManager.getConnection("jdbc:mysql://localhost:12345/db?characterEncoding=utf-8","root","lovo");
//            执行sql语句
            ps = con.prepareStatement("insert into t_link(l_name,l_date,l_sex,l_phone)"+"values(?,?,?,?)");

//            填充占位语句
            ps.setObject(1,linkBean.getName());
            ps.setObject(2,linkBean.getDate());
            ps.setObject(3,linkBean.getSex());
            ps.setObject(4,linkBean.getPhone());

//            刷新数据
            ps.executeUpdate();

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
//                释放数据
                con.close();
                ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void del(int id) {

    }

    @Override
    public void update(int id, String phone) {

    }

    @Override
    public List<LinkBean> findAll() {
        return null;
    }

    @Override
    public LinkBean findById(int id) {
        return null;
    }

    @Override
    public List<LinkBean> findByName(String name) {
        return null;
    }

    public static void main(String[] args) {
        ILinkDao dao = new LinkDaoImols();
        dao.add(new LinkBean("刘", LocalDate.parse("1999-05-03"),"男","18402888588"));
    }
}
